package com.word.app.controller;

import java.util.*;

import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.word.app.controller.response.BaseResponse;
import com.word.app.pojo.Exam;
import com.word.app.pojo.dto.PagingReq;
import com.word.app.service.IExamService;

/**
 * @author nano
 */
@RestController
@RequestMapping("/exam")
public class ExamController {
    @Autowired
    IExamService service;

    @RequiresPermissions(value={"perm:root", "perm:visitor"}, logical = Logical.OR)
    @PostMapping("/query")
    public BaseResponse query(@RequestBody PagingReq<Exam> req) {
        QueryWrapper<Exam> wrapper = new QueryWrapper<Exam>();
        wrapper.setEntity(req.getParams());
        return new BaseResponse().data(service.page(req.getPage(), wrapper));
    }
    

    @RequiresPermissions(value="perm:root")
    @PostMapping("/add")
    public void add(@RequestBody Exam question){
        service.save(question);
    }

    @RequiresPermissions(value="perm:root")
    @PostMapping("/delete")
    public void delete(@RequestBody List<String> ids){
        service.removeByIds(ids);
    }

}
